﻿using System;
using System.Collections;
using NUnit.Framework;
using Smartkernel;
using Smartkernel.Caching;

namespace Smartkernel.NUnitTest.Caching
{
    [Category("Caching")]
    [TestFixture]
    public class SmartCacherKeyTest
    {
        [Test]
        public void Test()
        {
            //【01】测试两个特性是否相等（涉及方法：Equals）
            SmartCacherKey<string> key1 = new SmartCacherKey<string>("SmartCacherKeyTestA", "Key");
            SmartCacherKey<string> key2 = new SmartCacherKey<string>("SmartCacherKeyTestA", "Key");
            SmartCacherKey<string> key3 = new SmartCacherKey<string>("SmartCacherKeyTestB", "Key");
            Assert.AreEqual(key1.Equals(key2), true);
            Assert.AreEqual(key1.Equals(key3), false);

            //【02】测试SmartCacherKey类型作为键的情况（涉及方法：GetHashCode、Equals）
            Hashtable hashtable = new Hashtable();
            string ticks = DateTime.Now.Ticks.ToString();
            hashtable.Add(key1, ticks);
            Assert.AreEqual(hashtable[key2].ToString(), ticks);
            Assert.AreEqual(hashtable[key3], null);

            //【03】测试构造函数参数为空是引发异常（涉及方法：构造函数）
            Assert.AreEqual(SmartAction.IsInvokeFail(delegate { new SmartCacherKey<string>(" ", " "); }), true);
            Assert.AreEqual(SmartAction.IsInvokeFail(delegate { new SmartCacherKey<string>(null, null); }), true);
        }
    }
}
